<?php
include('../../../cfg/cfg.inc.php');
include('../../../include/functions.inc.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Estado de Cuenta</title>
        <link href="../../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="../../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <link href="../../../js/protocalendar/datepicker.css" rel="stylesheet" type="text/css" />
        <script src="../../../js/jquery.js" type="text/javascript"></script>
        <script>jQuery.noConflict();</script>
        <script src="../../../bootstrap/js/bootstrap.js"></script>
        <script src="../../../js/prototype.js" type="text/javascript"></script>
        <script src="../../../js/jsvalidate.js" type="text/javascript"></script>
        <script  src="../../../js/proto-load/protoload.js" type="text/javascript"></script>
        <script src="../../../js/protocalendar/prototype-date-extensions.js" type="text/javascript"></script>
        <script src="../../../js/protocalendar/datepicker.js"  type="text/javascript"></script>
        <script src="../../../js/TableOrderer.js" type="text/javascript"></script>
        <script src="../../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../../js/include.js" type="text/javascript"></script>
        <script type="text/javascript">
            showSolvencia=function(){
                new Dialog({
                    title:'Solvencia',
                    width:'max',
                    height:'max',
                    padding:0,
                    margin:75,
                    iframe:'solvenciaData.php?estud='+$F("ID")
                }).open();
            }
            var rsv,rsv2;
            config=function(){
                rsv=new RSV({
                    formID: $(document.ASIGNACION),
                    errorFieldClass: "errorField",
                    rules: ["digits_only,ID,Carnet es numerico!"],
                    displayType : "display-html",
                    errorHTMLItemBullet : "&#8212; ",
                    onCompleteHandler:function(){
                        $('operation').value=($('ID').id==2)?'aiu':'id';
                        $(document.ASIGNACION).request({onComplete:function(r){
                                res=r.responseJSON;
                                if(res.ERROR){
                                    alert(res.ERROR);
                                }else{
                                    $('ID').value=res.ID;
                                    $('ACCOUNT').value=res.ACCOUNT;
                                    $('SACTUAL').value=res.SALDO_VENCIDO;
                                    $('SANTERI').value=res.SALDO_PENDIENTE;
                                    $('student').value=1;
                                    if( parseFloat(res.SALDO_VENCIDO) > 0 || parseFloat(res.CHEQUE_RECHAZADO) == 1 ) {
                                        strEstado = '';
                                        if( parseFloat(res.SALDO_VENCIDO) > 0 ) { 
                                            strEstado += 'No Solvente<br/>';
                                        }
                                        if( parseFloat(res.CHEQUE_RECHAZADO) == 1 ) { 
                                            strEstado += 'El estudiante tiene cheque(s) rechazado(s)!!!';
                                        }
                                        $("estado").update(strEstado);
                                        $("print").disabled=true;
                                    }
                                    else{
                                        $("estado").update("Solvente");
                                        $("print").disabled=false;
                                    }
                                    rsv2.validate();
                                }
                            }});

                    }});

                rsv2=new RSV({	formID: $(document.ASIGNACION),
                    errorFieldClass: "errorField",
                    rules: ["required,NAME,Debe seleccionar un estudiante!"],
                    displayType : "display-html",
                    errorHTMLItemBullet : "&#8212; ",
                    onCompleteHandler:function(){
                        if($F('student') == 1){
                            $("operation").value='cargos';
                            waitMsg("Cargando Datos...")
                            $('cargos').update("");
                            $('pendientes').update("");
                            new Ajax.Updater('cargos',$(document.ASIGNACION).action,
                            { parameters:Form.serialize($(document.ASIGNACION)),
                                onComplete:function(){
                                    $("operation").value='abonos';
                                    new Ajax.Updater('pendientes',$(document.ASIGNACION).action,
                                    { parameters:Form.serialize($(document.ASIGNACION)),
                                        onComplete:function(){
                                            closeWait();
                                        }});

                                }});

                        }else{
                            alert('Busque un estudiante para realizar la busqueda!');
                        }
                    }});
            }

            addOnLoad(config);
            showStud=function(){
                var f=new Hash({tittle:'Listado de Alumnos',
                    url:'data.php?operation=stud',
                    callback:selStudent,width:500,height:700});
                setList(null,f.toObject());
            }

            selStudent=function(s){
                $("ID").value=s.CARNET;
                $("NAME").value=s.NOMBRE_A+' '+s.NOMBRE_B+' '+s.APELLIDOS;
                rsv.validate();
            }
			
        </script>
    </head>

    <body>
        <div id="rsvErrors"></div>
        <form id="ASIGNACION" name="ASIGNACION" method="GET" action="data.php">
            <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th scope="col"><ul class="nav nav-tabs"><li class="active"><a>Estado de Cuenta</a></li></ul></th>
                </tr>
                <tr>
                    <td>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="25%"> NO. CARNET:</td>
                                <td width="75%">            <input name="ID" type="text" readonly="readonly" id="ID" />
                                    <input name="buscar" type="button" onclick="showStud()" class="btn btn-small" id="buscar"  value="..." /></td>
                            </tr>
                            <tr>
                                <td>NOMBRE ESTUDIANTE:</td>
                                <td><input name="NAME" type="text" id="NAME" readonly="readonly" size="50" /></td>
                            </tr>
                            <tr>
                                <td>SALDO VENCIDO:</td>
                                <td><input type="text" readonly="readonly" name="SACTUAL" id="SACTUAL" /></td>
                            </tr>
                            <tr>
                                <td>SALDO PENDIENTE:</td>
                                <td><input type="text" name="SANTERI" readonly="readonly" id="SANTERI" />
                                    <input type="hidden" name="ACCOUNT" id="ACCOUNT" />
                                    <input type="hidden" name="operation" id="operation" />
                                    <input name="student" type="hidden" id="student" value="0" /></td>
                            </tr>
                            <tr>
                                <td>ESTADO:</td>
                                <td><div id="estado"></div></td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td><div class="btn-group"><input name="ver" type="button" class="btn btn-info" onclick="rsv2.validate();" id="ver" value="Actualizar" />
                                    <input name="print" disabled="disabled" onclick="javascript:showSolvencia();" type="button" class="btn btn-info" id="print" value="Solvencia" /></div></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <th scope="col"><legend>Pagos Vencidos</legend></th>
                </tr>
                <tr>
                    <td colspan="2"><div id="cargos" style="width:100%;"></div></td>
                </tr>
                <tr>
                    <th scope="col"><legend>Cargos a Pagar</legend></th>
                </tr>
                <tr>
                    <td colspan="2"><div id="pendientes" style="width:100%;"></div></td>
                </tr>
            </table>
        </form>
    </body>
</html>
